<html><head><title>Functions to fit local regression</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="Rchm.css">
</head>
<body>

<table width="100%"><tr><td>Locmean(gamlss.util)</td><td align="right">R Documentation</td></tr></table><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
<param name="keyword" value="R:   Locmean">
<param name="keyword" value="R:   Locpoly">
<param name="keyword" value="R:   WLocmean">
<param name="keyword" value="R:   WLocpoly">
<param name="keyword" value=" Functions to fit local regression">
</object>


<h2>Functions to fit local regression</h2>


<h3>Description</h3>

<p>
There are four function here to illustrate the fitting of local regressions.
i) <code>Locmean</code>, which uses local means within a symmetric local window,
ii) <code>Locpoly</code>, which uses a local polynomial fit within a symmetric local window.
iii) <code>WLocmean</code>, which uses a Gaussian kernel and
iv)  <code>WLocpoly</code>, which uses local polynomials weighted by a Gaussian kernel
</p>


<h3>Usage</h3>

<pre>
Locmean(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5)
Locpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5, order = 1)
WLocmean(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5)
WLocpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5, order = 1)
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>y</code></td>
<td>
the response variable</td></tr>
<tr valign="top"><td><code>x</code></td>
<td>
the x-variable</td></tr>
<tr valign="top"><td><code>w</code></td>
<td>
prior weights</td></tr>
<tr valign="top"><td><code>span</code></td>
<td>
the side of the local window compare as a proportion to the total number of observations</td></tr>
<tr valign="top"><td><code>lambda</code></td>
<td>
the smoothing parameter for the Gaussian kernel</td></tr>
<tr valign="top"><td><code>order</code></td>
<td>
the order of the polynomial</td></tr>
</table>

<h3>Details</h3>

<p>
Those functions can be  used for illustration of the basic concepts of smoothing using small data sets. 
Do not use them with large data because are computationally inefficient.
</p>


<h3>Value</h3>

<p>
The functions return a <code>locW</code> object with values 
</p>
<table summary="R argblock">
<tr valign="top"><td><code>fitted.values</code></td>
<td>
the fitted valus</td></tr>
<tr valign="top"><td><code>residuals</code></td>
<td>
the residuals</td></tr>
<tr valign="top"><td><code>edf</code></td>
<td>
the effective degrees of freedom</td></tr>
<tr valign="top"><td><code>rss</code></td>
<td>
the residual sum of squares</td></tr>
<tr valign="top"><td><code>lambda</code></td>
<td>
the smoothing parameter</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
the y variable</td></tr>
<tr valign="top"><td><code>x</code></td>
<td>
the x variable</td></tr>
<tr valign="top"><td><code>w</code></td>
<td>
the prior weights</td></tr>
</table>

<h3>Author(s)</h3>

<p>
Mikis Stasinopoulos, <a href="mailto:d.stasinopoulos@londonmet.ac.uk">d.stasinopoulos@londonmet.ac.uk</a>
</p>


<h3>References</h3>

<p>
Rigby, R. A. and  Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), 
<EM>Appl. Statist.</EM>, <B>54</B>, part 3, pp 507-554.
</p>
<p>
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R.
Accompanying documentation in the current GAMLSS  help files, (see also  <a href="http://www.gamlss.com/">http://www.gamlss.com/</a>) 
</p>
<p>
Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R.
<EM>Journal of Statistical Software</EM>, Vol. <B>23</B>, Issue 7, Dec 2007, <a href="http://www.jstatsoft.org/v23/i07">http://www.jstatsoft.org/v23/i07</a>.
</p>


<h3>See Also</h3>

<p>
<code><a onclick="findlink('stats', 'loess.html')" style="text-decoration: underline; color: blue; cursor: hand">loess</a></code>, <code><a onclick="findlink('stats', 'ksmooth.html')" style="text-decoration: underline; color: blue; cursor: hand">ksmooth</a></code>
</p>


<h3>Examples</h3>

<pre>
library(MASS)
data(mcycle)
# local means
m0&lt;-Locmean(mcycle$accel, mcycle$times, span=.1)
m1&lt;-Locmean(mcycle$accel, mcycle$times, span=.2)
m2&lt;-Locmean(mcycle$accel, mcycle$times, span=.3)
span &lt;- c("span=0.1", "span=0.2", "span=0.3")
plot(accel~times, data=mcycle,main="local mean")
lines(fitted(m0)~mcycle$times, col=1, lty=1)
lines(fitted(m1)~mcycle$times, col=2, lty=2)
lines(fitted(m2)~mcycle$times, col=3, lty=3)
legend(1.5,50, legend = span, col = 1:3,
       lty = 1:3, cex = .8, y.intersp = 1)
#  kernel estimation      
k0&lt;-WLocmean(mcycle$accel, mcycle$times, lambda=1)
k1&lt;-WLocmean(mcycle$accel, mcycle$times,  lambda=2)
k2&lt;-WLocmean(mcycle$accel, mcycle$times,  lambda=3)
lambda &lt;- c("lambda=1", "lambda=2", "lambda=3")
plot(accel~times, data=mcycle,main="Gaussian kernel fit")
lines(fitted(k0)~mcycle$times, col=1, lty=1)
lines(fitted(k1)~mcycle$times, col=2, lty=2)
lines(fitted(k2)~mcycle$times, col=3, lty=3)
legend(1.5,50, legend = lambda, col = 1:3,
       lty = 1:3, cex = .8, y.intersp = 1)
# local polymials
l1&lt;-Locpoly(mcycle$accel, mcycle$times, span=.1)
l2&lt;-Locpoly(mcycle$accel, mcycle$times, span=.2)
l3&lt;-Locpoly(mcycle$accel, mcycle$times, span=.3)

span &lt;- c("span=0.1", "span=0.2", "span=0.3")
plot(accel~times, data=mcycle,main="local linear fit")
lines(fitted(l1)~mcycle$times, col=1, lty=1)
lines(fitted(l2)~mcycle$times, col=2, lty=2)
lines(fitted(l2)~mcycle$times, col=3, lty=3)
legend(1.5,50, legend = span, col = 1:3,
       lty = 1:3, cex = .8, y.intersp = 1)       
# weighted local polynomials  
lw1&lt;-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=1)
lw2&lt;-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=2)
lw3&lt;-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=3)

span &lt;- c("linear", "quadratic", "cubic")
plot(accel~times, data=mcycle,main="Weighted local linear, quadratic and cubic fits")
lines(fitted(lw1)~mcycle$times, col=1, lty=1)
lines(fitted(lw2)~mcycle$times, col=2, lty=2)
lines(fitted(lw3)~mcycle$times, col=3, lty=3)
legend(1.5,50, legend = span, col = 1:3,
       lty = 1:3, cex = .8, y.intersp = 1)     
</pre>

<script Language="JScript">
function findlink(pkg, fn) {
var Y, link;
Y = location.href.lastIndexOf("\\") + 1;
link = location.href.substring(0, Y);
link = link + "../../" + pkg + "/chtml/" + pkg + ".chm::/" + fn;
location.href = link;
}
</script>


<hr><div align="center">[Package <em>gamlss.util</em> version 0.0-2 <a href="00Index.html">Index</a>]</div>

</body></html>
